﻿@{
    Layout = "_ZjcLayout";
    ViewData["Title"] = "政教处";
}

<fieldset class="layui-elem-field" style="margin: 20px">
    <legend>工作计划审核状态</legend>
    <div class="layui-field-box">
        <table class="layui-table" id="fileList2"></table>
    </div>
</fieldset>

@section Scripts{
    <script src="~/layui-v2.5.5/layui/layui.all.js" charset="utf-8"></script>
    <script src="~/js/jquery.js"></script>
    <script>
        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;
            //多文件列表示例
            var demoListView = $('#fileList')
                , uploadListIns = upload.render({
                    elem: '#fileChoose'
                    , url: '/api/upload'
                    , accept: 'file'
                    , multiple: true
                    , auto: false
                    , bindAction: '#testListAction'
                    , choose: function (obj) {
                        var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                        //读取本地文件
                        obj.preview(function (index, file, result) {
                            var tr = $(['<tr id="upload-' + index + '">'
                                , '<td>' + file.name + '</td>'
                                , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                                , '<td>等待上传</td>'
                                , '<td>'
                                , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                                , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                                , '</td>'
                                , '</tr>'].join(''));

                            //单个重传
                            tr.find('.demo-reload').on('click', function () {
                                obj.upload(index, file);
                            });

                            //删除
                            tr.find('.demo-delete').on('click', function () {
                                delete files[index]; //删除对应的文件
                                tr.remove();
                                layer.msg('删除成功');
                                uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                            });

                            demoListView.append(tr);
                        });
                    }
                    , done: function (res, index, upload) {
                        if (res.code == 0) { //上传成功
                            layer.alert('所有文件上传完毕！', { icon: 6 });
                            var tr = demoListView.find('tr#upload-' + index)
                                , tds = tr.children();
                            tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                            tds.eq(3).html(''); //清空操作
                            return delete this.files[index]; //删除文件队列已经上传成功的文件
                        }
                        this.error(index, upload);
                    }
                    , error: function (index, upload) {
                        var tr = demoListView.find('tr#upload-' + index)
                            , tds = tr.children();
                        tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                        tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
                    }
                });
        });

    </script>
    <script type="text/html" id="button">
        {{#  if(d.state === '已驳回'){ }}
        <span style="color: #FF0033;">{{ d.state }}</span>
        {{#  } else if(d.state === '已通过') { }}
        <span style="color:#3BA250;">{{ d.state }}</span>
        {{#  } else if(d.state === '等待审核') { }}
        <span style="color: #1111EE;">{{ d.state }}</span>
        {{#  } else if(d.state === '等待修正') { }}
        <span style="color: #EE6911;">{{ d.state }}</span>
        {{#  } else { }}
        <span style="color: #4D76B3;">{{ d.state }}</span>
        {{#  } }}
    </script>

    <script>
        layui.use('table', function () {
            var table = layui.table;
            $.ajax({
                url: '/Api/QueryAllFile',
                type: "POST",
                dataType: "JSON",
                success: function (res) {
                    table.render({
                        elem: '#fileList2'
                        , cols: [[
                            { field: 'id', width: "5%", title: 'ID', sort: true }
                            , { field: 'teacherName', width: "13%", title: '上传者' }
                            , { field: 'filepath', width: "20%", title: '文件路径', }
                            , { field: 'filename', width: "10%", title: '文件名' }
                            , { field: 'committime', title: '上传时间', minWidth: 150, sort: true }
                            , { field: 'state', title: '当前状态', minWidth: 150,templet: '#button' }
                            , { field: 'issue', title: '原因或意见', minWidth: 150, }
                        ]]
                        , data: res.data
                        , page: true
                        , height:472
                    });
                }
            });

        });
    </script>

}